<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>编辑入住人 - 活力长者社区</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        .edit-container {
            max-width: 800px;
            margin: 30px auto;
            padding: 25px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        }

        .page-header {
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid #e9ecef;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-label {
            font-weight: 500;
            margin-bottom: 8px;
        }

        .btn-save {
            background-color: #28a745;
            border-color: #28a745;
            width: 100%;
            padding: 10px;
            font-size: 1.1rem;
        }

        .btn-save:hover {
            background-color: #218838;
            border-color: #1e7e34;
        }
    </style>
</head>
<body>
<c:import url="header.jsp" />

<div class="edit-container">
    <div class="page-header">
        <h2><i class="bi bi-pencil-square"></i> 编辑入住人信息</h2>
        <p class="text-muted">修改入住人的详细信息并保存</p>
    </div>

    <c:if test="${not empty error}">
        <div class="alert alert-danger">${error}</div>
    </c:if>

    <c:if test="${not empty occupant}">
        <form action="EditOccupantServlet" method="post">
            <input type="hidden" name="residenceId" value="${occupant.residenceId}">

            <div class="form-group">
                <label class="form-label">姓名</label>
                <input type="text" name="occupantName" class="form-control"
                       value="${occupant.occupantName}" required>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="form-label">年龄</label>
                        <input type="number" name="age" class="form-control"
                               value="${occupant.age}" min="0" max="120" required>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="form-label">性别</label>
                        <select name="gender" class="form-select" required>
                            <option value="男" ${occupant.gender eq '男' ? 'selected' : ''}>男</option>
                            <option value="女" ${occupant.gender eq '女' ? 'selected' : ''}>女</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="form-label">与您的关系</label>
                <select name="relationship" class="form-select" required>
                    <option value="配偶" ${occupant.relationship eq '配偶' ? 'selected' : ''}>配偶</option>
                    <option value="子女" ${occupant.relationship eq '子女' ? 'selected' : ''}>子女</option>
                    <option value="父母" ${occupant.relationship eq '父母' ? 'selected' : ''}>父母</option>
                    <option value="兄弟姐妹" ${occupant.relationship eq '兄弟姐妹' ? 'selected' : ''}>兄弟姐妹</option>
                    <option value="朋友" ${occupant.relationship eq '朋友' ? 'selected' : ''}>朋友</option>
                    <option value="其他" ${occupant.relationship eq '其他' ? 'selected' : ''}>其他</option>
                </select>
            </div>

            <div class="form-group">
                <label class="form-label">入住类型</label>
                <select name="residenceType" class="form-select" required>
                    <option value="长期居住" ${occupant.residenceType eq '长期居住' ? 'selected' : ''}>长期居住</option>
                    <option value="短期居住" ${occupant.residenceType eq '短期居住' ? 'selected' : ''}>短期居住</option>
                    <option value="试住" ${occupant.residenceType eq '试住' ? 'selected' : ''}>试住</option>
                    <option value="康复居住" ${occupant.residenceType eq '康复居住' ? 'selected' : ''}>康复居住</option>
                </select>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="form-label">入住时间</label>
                        <input type="date" name="startTime" class="form-control"
                               value="<fmt:formatDate value='${occupant.startTime}' pattern='yyyy-MM-dd' />" required>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <label class="form-label">计划离开时间</label>
                        <input type="date" name="endTime" class="form-control"
                               value="<fmt:formatDate value='${occupant.endTime}' pattern='yyyy-MM-dd' />">
                        <small class="form-text text-muted">长期居住可不填</small>
                    </div>
                </div>
            </div>

            <div class="d-grid gap-2 mt-4">
                <button type="submit" class="btn btn-primary btn-save">
                    <i class="bi bi-check-circle"></i> 保存修改
                </button>
                <a href="ViewOccupantsServlet" class="btn btn-secondary">
                    <i class="bi bi-x-circle"></i> 取消并返回
                </a>
            </div>
        </form>
    </c:if>

    <c:if test="${empty occupant}">
        <div class="alert alert-warning">未找到入住人信息</div>
        <a href="ViewOccupantsServlet" class="btn btn-primary">返回列表</a>
    </c:if>
</div>

<c:import url="footer.jsp" />

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>